// pages/shopCar/embit/embit.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    addressList:[],
    embitAddress:{},
  },
  family(e){
    let embitAddress = this.data.embitAddress;
    embitAddress.name = e.detail.value;
      this.setData({
        embitAddress:embitAddress,
      })
  },
  tel(e){
    let embitAddress = this.data.embitAddress;
    embitAddress.phone = e.detail.value;
    this.setData({
      embitAddress:embitAddress,
    })

  },
  contry(e){
    let embitAddress = this.data.embitAddress;
    embitAddress.procince = e.detail.value.substring(0,2);
    embitAddress.city = e.detail.value.substring(2,4);
    embitAddress.area = e.detail.value.substring(4);
    
    this.setData({
      embitAddress:embitAddress,
    })
    
  },
  town(e){
    let embitAddress = this.data.embitAddress;
    embitAddress.detailed = e.detail.value;
    this.setData({
      embitAddress:embitAddress,
    })
     console.log(this.data.detailed)
  },
getAddressInfo(e){
  let that = this;
  wx.request({
    url: 'http://api_devs.wanxikeji.cn/api/userAddressAddModify?token=3c35c3d0738a879f23926f4676b2874e',
    method:"POST",
    data:{
      ...this.data.embitAddress
    },
    header: {
      'content-type': 'application/json' // 默认值
    },
    success:function(res){
      console.log(res.data)
      that.setData({
        embitAddress:res.data.data
      })
    }
  });
  let pages = getCurrentPages();
  let prePage = pages[pages.length - 3];   
  prePage.setData({
      getAddress:that.data.embitAddress
  })
  wx.navigateBack({
    delta:2,
  })
},
delAddressInfo(){
  let id = this.data.embitAddress.address_id;
  let that = this;
    wx.request({
      url: 'http://api_devs.wanxikeji.cn/api/userAddressDelete?token=3c35c3d0738a879f23926f4676b2874e',
      method:"POST",
      data:{
        id:id,
      },
      success:function(res){
        console.log(res);
        that.setData({
          addressList:addressList
        })
      }
    })
    
    wx.navigateBack({
      delta:1,
    })
},
 /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let object = JSON.parse(options.emInfo);
    this.setData({
      embitAddress:object
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log(this.data.embitAddress)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})